export default {
  namespaced: true,
  state: {
    productData: [],
  },
  getters: {},
  mutations: {
    CART(state, payload) {
      state.productData = payload;
    },
    JIANJIA(state,payload){
      console.log(payload);
      payload.inventory--
    },
    JIA(state,payload){
      console.log(payload);
      let target = state.productData.find(item=>item.id===payload.id)
      console.log(target);
      if (target) {
        target.inventory++
      }
      
      
    },
  },
  actions: {
  async FETCH(context, payload) {
    let res = await fetch("http://chst.vip/data/index.json").then((body) =>
      body.json()
    );
    context.commit("CART", res.data);
    console.log(res);
  },
  JIANA(context,payload){
    context.commit('JIANJIA',payload)
  }
}
}